﻿namespace Smart.Utils.UI.BarcodeLib
{
    using System;

    internal class Interleaved2of5 : BarcodeCommon, IBarcode
    {
        private string[] I25_Code = new string[] { "NNWWN", "WNNNW", "NWNNW", "WWNNN", "NNWNW", "WNWNN", "NWWNN", "NNNWW", "WNNWN", "NWNWN" };

        public Interleaved2of5(string input)
        {
            base.Raw_Data = input;
        }

        private string Encode_Interleaved2of5()
        {
            if ((base.Raw_Data.Length % 2) != 0)
            {
                throw new Exception("EI25-1: Data length invalid.");
            }
            if (!BarcodeEdit.CheckNumericOnly(base.Raw_Data))
            {
                throw new Exception("EI25-2: Numeric Data Only");
            }
            string str = "1010";
            for (int i = 0; i < base.Raw_Data.Length; i += 2)
            {
                bool flag = true;
                char ch2 = base.Raw_Data[i];
                string str2 = this.I25_Code[int.Parse(ch2.ToString())];
                ch2 = base.Raw_Data[i + 1];
                string str3 = this.I25_Code[int.Parse(ch2.ToString())];
                string str4 = "";
                while (str2.Length > 0)
                {
                    ch2 = str2[0];
                    ch2 = str3[0];
                    str4 = str4 + ch2.ToString() + ch2.ToString();
                    str2 = str2.Substring(1);
                    str3 = str3.Substring(1);
                }
                foreach (char ch in str4)
                {
                    if (flag)
                    {
                        if (ch == 'N')
                        {
                            str = str + "1";
                        }
                        else
                        {
                            str = str + "11";
                        }
                    }
                    else if (ch == 'N')
                    {
                        str = str + "0";
                    }
                    else
                    {
                        str = str + "00";
                    }
                    flag = !flag;
                }
            }
            return (str + "1101");
        }

        public string Encoded_Value
        {
            get
            {
                return this.Encode_Interleaved2of5();
            }
        }
    }
}

